package com.orange.lockscreen.anims;

import android.view.animation.Transformation;
import android.view.animation.TranslateAnimation;

public class LCTranslateAnimation extends TranslateAnimation {

	private static final String	TAG			= "LCTranslateAnimation";

	private float				mFromXValue	= 0.0f;
	private float				mToXValue	= 0.0f;
	private float				mFromYValue	= 0.0f;
	private float				mToYValue	= 0.0f;
	private OnTranslateListener	mListener	= null;

	public LCTranslateAnimation(float fromXDelta, float toXDelta,
			float fromYDelta, float toYDelta) {
		super(fromXDelta, toXDelta, fromYDelta, toYDelta);
		mFromXValue = fromXDelta;
		mToXValue = toXDelta;
		mFromYValue = fromYDelta;
		mToYValue = toYDelta;
	}

	@Override
	protected void applyTransformation(float interpolatedTime, Transformation t) {
		super.applyTransformation(interpolatedTime, t);

		float dx = mFromXValue;
		float dy = mFromYValue;
		if (mFromXValue != mToXValue) {
			dx = mFromXValue + ((mToXValue - mFromXValue) * interpolatedTime);
		}
		if (mFromYValue != mToYValue) {
			dy = mFromYValue + ((mToYValue - mFromYValue) * interpolatedTime);
		}
		if (null != mListener) {
			mListener.onTranslate(dx, dy);
		}
	}

	public void setOnTranslateListener(OnTranslateListener listener) {
		mListener = listener;
	}

	public interface OnTranslateListener {
		public void onTranslate(float dx, float dy);
	}
}
